package tests

import (
	"testing"
	"time"

	zipkin "github.com/openzipkin/zipkin-go"
	httpreporter "github.com/openzipkin/zipkin-go/reporter/http"
)

func TestZipkin(t *testing.T) {
	reporter := httpreporter.NewReporter("http://localhost:9411/api/v2/spans")
	defer reporter.Close()
	endpoint, err := zipkin.NewEndpoint("demoService", "127.0.0.1:222")
	if err != nil {
		t.Error(err)
		return
	}
	tracer, err := zipkin.NewTracer(
		reporter,
		zipkin.WithLocalEndpoint(endpoint),
		zipkin.WithTags(map[string]string{
			"a": "aa",
			"b": "bb",
		}),
	)
	if err != nil {
		t.Error(err)
		return
	}
	span := tracer.StartSpan("some_operation")
	subSpan := tracer.StartSpan("xxx", zipkin.Parent(span.Context()))
	time.Sleep(100 * time.Millisecond)
	subSpan.Finish()
	time.Sleep(100 * time.Millisecond)
	span.Finish()
}
